package mspbots.hubspot.client.core.tickets;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import mspbots.hubspot.common.QueryBody;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.Map;

/**
 * data.connector.hubspot.api.contatct.ContactController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2020/3/31
 */
@RestController
@RequestMapping("tickets/{tenantId}")
@RequiredArgsConstructor
public class TicketsController {

    private final TicketsServiceImpl ticketsService;

    @PostMapping("create")
    public Mono<JsonNode> create(@PathVariable Long tenantId, @Valid @RequestBody Map<String, Object> properties) {
        return this.ticketsService.create(tenantId, properties);
    }

    @GetMapping("properties")
    public Flux<JsonNode> properties(@PathVariable Long tenantId) {
        return this.ticketsService.properties(tenantId);
    }

    @PostMapping("search")
    public Flux<JsonNode> search(@PathVariable Long tenantId, @Valid @RequestBody QueryBody queryBody) {
        return this.ticketsService.search(tenantId, queryBody);
    }

}
